"""
@ProjectName : Game
@File        : clip.py
@Author      : WorldWind(1772830365@qq.com)
@Address     : ChangSha - BoWeiFeng
@Date        : 2025/7/17 下午3:56
"""


# 子弹弹夹
class Clip:
    def __init__(self, capacity):
        self.capacity = capacity
        # 子弹[列表] 列表模拟弹夹
        self.bulletList = []
        print(f'This is __init__ method. {self.get_class_name()} class startup')

    # 装子弹
    def loadBullets(self, bullet):
        # 如果弹夹没满,就可以继续装子弹
        if len(self.bulletList) < self.capacity:
            self.bulletList.append(bullet)
        else:
            print("弹夹已满!")
    # 显示弹夹中有多少子弹
    def showBulletCounts(self):
        print(len(self.bulletList))
        return len(self.bulletList)
    def shootBullet(self):
        if len(self.bulletList) <= 0:
            return None
        else:
            # 弹出子弹
            bullet = self.bulletList[-1]
            self.bulletList.pop()
            return bullet

    @classmethod
    def get_class_name(cls):
        return cls.__name__

    def __del__(self):
        print(f'This is __del__ method. The {self.get_class_name()} class has been recycled')
